angular.module('Controller')

.controller('EdRechargeManageCtrl', ($scope,NgTableParams,commonUtil,commonConstant,menuManage,$rootScope,$http) ->
    initSearchData = ()->
        $scope.search = {
            filter: undefined ,
            status: 2
        }
    initSearchData()
    $scope.tableParams = new NgTableParams(
        {page: 1, count: 10},
        {
            counts: [5, 10, 20],
            getData: ($defer, params)->
                $scope.doQuery($defer,params)
                return ;
        }
    )
    $scope.doQuery=($defer, params)->
        requestData={
            page: params.page() - 1,
            size: params.count(),
            filter: $scope.search.filter
            status: $scope.search.status
        }
        $http.get('/balance/recharge', params:requestData)
        .success (resp)->
            if resp.code==0
                console.log(resp.message);
                $scope.tableData = resp.message.content;
                $defer.resolve($scope.tableData);
                params.total(resp.message.totalElements)
            else
                console.log(resp.message)
        .error (err)->
            console.log(err)
    _.extend $scope,
        detailNews:(data)->
            $rootScope.pageData = data
            console.log(data)
            menuManage.goState('recharge-detail',true)
        resetSearch: ->
            initSearchData()
        queryData: (keepPage)->
            if(keepPage != true)
                $scope.tableParams.page(1)
            $scope.tableParams.reload()
)